package com.sinog.front.controller.biz;

import com.sinog.core.model.UserDTO;
import com.sinog.core.util.JsonUtil;
import com.sinog.core.utilbean.Result;
import com.sinog.front.config.log.Log;
import com.sinog.front.feign.biz.BjdxMvInfoService;
import com.sinog.front.service.user.UserFacade;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @desc 户籍迁入人员管理
 * @author sunsf
 * @date 2020-02-07-13:51
 */
@RestController
@Slf4j
public class HjqrryglController {

    @Resource
    private BjdxMvInfoService bjdxMvInfoService;
    @Resource
    private UserFacade userFacade;

    /**
     * 安置帮教管理 - 帮教对象信息管理 - 户籍迁入人员管理 - 列表
     * @param pageIndex pageIndex
     * @param pageSize pageSize
     * @param sortField 排序字段
     * @param sortOrder 排序方式
     * @param request request
     * @return String
     */
    @RequestMapping("/azbj/azbjgl/bjdxInfo/hjqrrygl/list")
    public String toHjqrryglPublicList(Integer pageIndex,Integer pageSize,String sortField,String sortOrder,HttpServletRequest request) {
        String key = request.getParameter("querykey");
        UserDTO user = userFacade.getAuthentication();
        String departId = user.getDepartid();
        int level = Integer.parseInt(user.getLevel());
        String orgid = user.getOrgid();
        return bjdxMvInfoService.getHjqrglList(pageIndex,pageSize,key,departId,level,orgid,sortField,sortOrder);
    }

    /**
     * 安置帮教管理 - 帮教对象信息管理 - 户籍迁入人员管理 - 审核页面 - 保存
     * @param request request
     * @param data data
     * @return Result
     */
    @Log(type = "更新", value = "户籍迁入上级审核")
    @RequestMapping("/azbj/bjdxInfo/hjqr/shenheSave")
    public Result shenheSave(HttpServletRequest request,
                             @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO user = userFacade.getAuthentication();
        data = JsonUtil.setObjectToJsonStr(data, "updateUser",user.getAccount());
        return bjdxMvInfoService.saveBaseInfo(data);
    }

    /**
     * 安置帮教管理 - 帮教对象信息管理 - 户籍迁入人员管理 - 申请 - 保存
     * @param request request
     * @param data data
     * @return Result
     */
    @Log(type = "更新", value = "户籍迁入申请上级审核")
    @RequestMapping("/azbj/bjdxInfo/hjqr/saveMvInApplyInfo")
    public Result saveInfo(HttpServletRequest request,
                           @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO user = userFacade.getAuthentication();
        data = JsonUtil.setObjectToJsonStr(data, "updateUser",user.getAccount(), "updateTime",new Date());
        return bjdxMvInfoService.saveBaseInfo(data);
    }
}